package biz;

import entity.MobileCard;
import entity.NetPackage;
import entity.SuperPackage;
import entity.TalkPackage;
import tool.CardUtil;

import java.util.Scanner;

public class Common {
    CardUtil cardUtil = new CardUtil();
    public static void main(String[] args) {
            new Common().menu();
    }

    public void menu() {//主菜单，用于调用各个方法
        Scanner input = new Scanner(System.in);
        int choose = -1;
        String number = null,password = null;
        MobileCard temp = null;
        boolean isExist = false;
        do{
            loginInterface();
            choose = input.nextInt();
            switch (choose){
                case 1:
                    System.out.print("请输入手机卡号：");
                    number = input.next();
                    System.out.print("请输入密码：");
                    password = input.next();
                    isExist = cardUtil.find(number,password);
                    if (isExist) {
                        cardMenu(number);//登录成功时，进入二级菜单
                        isExist = true;
                    }else {
                        System.out.println("手机卡号或密码错误");
                    }
                    break;
                case 2:
                    register();//注册方法
                    break;
                case 3:
                    System.out.print("请输入手机卡号：");
                    number = input.next();
                        cardUtil.userSoso(number);//使用嗖嗖方法
                    break;
                case 4:
                    System.out.print("请输入手机卡号：");
                    number = input.next();
                    System.out.print("请输入充值额度：");
                    double changePrice = input.nextDouble();
                    cardUtil.chargeMoney(number,changePrice);//充值方法
                    break;
                case 5:
                    cardUtil.showPriceDescription();//显示资费信息方法
                    break;
                default:
                    System.out.println("谢谢使用，欢迎下次再来！");
                    System.exit(0);
            }
        }while(true);

    }
    public void cardMenu(String number){
        int choose = -1,choosePack = -1;
        Scanner input = new Scanner(System.in);
        do{
            sosoInterface();
            choose = input.nextInt();
            switch (choose){
                case 1:
                    cardUtil.showBillDetail(number);
                    break;
                case 2:
                    cardUtil.showRemaingDetail(number);
                    break;
                case 3:
                    cardUtil.printConsumeDetail(number);
                    break;
                case 4:
                    System.out.println("*********套餐变更*********");
                    do{
                        System.out.print("1.话痨套餐 2.网虫套餐 3.超人套餐（请选择套餐）：");
                        choosePack = input.nextInt();
                    }while(choosePack > 3 || choosePack < 1);
                    cardUtil.changePack(number,choosePack);
                    break;
                case 5:cardUtil.deleteCard(number);
                    break;
                default:
                    return;
            }
        }while (true);

    }
    public void register(){
        Scanner input = new Scanner(System.in);
        int choose = -1,choosePack = -1;
        double price = 0;
        MobileCard reg = new MobileCard();
        TalkPackage talkPackage = new TalkPackage();//注册时对套餐资费的初始化
        talkPackage.setPrice(58);
        NetPackage netPackage = new NetPackage();
        netPackage.setPrice(68);
        SuperPackage superPackage = new SuperPackage();
        superPackage.setPrice(78);
        System.out.println("**************可选择的卡号**************");
        String[] numbers = cardUtil.getNewNumber(9);//产生卡号方法
        for (int i = 0; i < numbers.length; i++) {//显示卡号供用户选择
            if (i > 0 && (i % 3 == 0)) {
                System.out.println();
            }
            System.out.print((i + 1) + "." + numbers[i] + "\t");
        }
        do{
            System.out.print("\n请选择卡号（输入1到9）：");
            choose = input.nextInt();
        }while (choose > 9 || choose < 1);//对错误输入小处理
        reg.setCardNumber(numbers[(choose - 1)]);
        do{
            System.out.print("1.话痨套餐 2.网虫套餐 3.超人套餐（请选择套餐）：");
            choosePack = input.nextInt();
        }while(choosePack > 3 || choosePack < 1);
        if(choosePack == 1){//对这个卡类的属性初始化
            reg.setSerPackage(talkPackage);
        }else if(choosePack == 2){
            reg.setSerPackage(netPackage);
        }else {
            reg.setSerPackage(superPackage);
        }
        System.out.print("请输入姓名：");
        reg.setUserName(input.next());
        System.out.print("请输入密码：");
        reg.setPassword(input.next());
        System.out.print("请输入预存金额：");
        price = input.nextDouble();
        while (price < reg.getSerPackage().getPrice()){//判断预存金额是否足够字符套餐资费
            System.out.print("你的金额不足以支付固定的套餐资费，请重新输入预存金额：");
            price = input.nextDouble();
        }
        reg.setConsume(reg.getSerPackage().getPrice());
        reg.setMoney(price - reg.getConsume());
        cardUtil.addCard(reg);
        System.out.print("注册成功！");
        reg.show();//打印相应的信息
        reg.getSerPackage().show();
    }
    public static void loginInterface(){//一级菜单页面
        System.out.println("************************欢迎使用嗖嗖移动业务大厅************************");
        System.out.println("1.用户登录   2.用户注册   3.使用嗖嗖   4.话费充值   5.资费说明   6.退出系统");
        System.out.print("请选择：");
    }
    public static void sosoInterface(){//二级菜单页面
        System.out.println("************************嗖嗖移动移动用户菜单************************");
        System.out.println("1.本月账单查询");
        System.out.println("2.套餐余量查询");
        System.out.println("3.打印消费详单");
        System.out.println("4.套餐变更");
        System.out.println("5.办理退网");
        System.out.print("请选择（1到5，其余键退回上一级）:");
    }
}
